package com.example.job_backend.controller;

import com.example.job_backend.model.R;
import com.example.job_backend.model.User;
import com.example.job_backend.service.UserService;
import com.example.job_backend.util.PasswordUtils;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user")
public class LoginController {
    @Resource
    UserService userService;

    @GetMapping("/login")
    public R login(String username, String password, String role) {
        String inputHash = PasswordUtils.md5WithSalt(password, "04943c669d0e4ca2830e402ceaa6242d");
        User user = userService.login(username, inputHash, role);
        if (user == null)
            return new R(1001, "用户名或密码错误", null);
        return new R(200, "登录成功", user);
    }
}
